//
//  LKOpenShopStepTwoViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/4.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKOpenShopStepTwoViewController.h"
#import "LKUFPictureRow.h"
#import "LKUFPictureRowCell.h"
#import "LKUFOpenShopHeaderRow.h"
#import "LKUFOpenShopHeaderRowCell.h"
#import "LKUFOpenShopBottomButtonRow.h"
#import "LKUFOpenShopBottomButtonRowCell.h"
#import "LKOpenShopStepThreeViewController.h"
@interface LKOpenShopStepTwoViewController (){
    dispatch_group_t _group;
    dispatch_queue_t _queue;
    dispatch_semaphore_t semaphore;
}

@property(nonatomic,strong)UFFormView *formview;
@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,assign)NSInteger pictureTapSelectIndex;
@property(nonatomic,strong)UIImage *selcetedUploadImage;
@end

@implementation LKOpenShopStepTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"商户开通";
    _group = dispatch_group_create();
    _queue = dispatch_queue_create("seriersQueue", DISPATCH_QUEUE_SERIAL);
      semaphore  = dispatch_semaphore_create(1);
    [self setNavgationRightBtn];
    self.dataArray = [[NSMutableArray alloc] initWithArray:@[@"ic_main_member_manage",@"ic_main_member_manage",@"ic_main_member_manage"]];
    if ([self.inforModel.mcc_jc_id isEqualToString:@"-1"]) {
        [self createPesonFormView];
    }else if ([self.inforModel.mcc_jc_id isEqualToString:@"3"]){
        [self createXiaoVFormView];
    }else{
        [self createFormView];
    }
    // Do any additional setup after loading the view.
}
-(void)setNavgationRightBtn{
    WS(weakSelf)
    LKBaseButton *rightBtn = [LKBaseButton buttonWithFrame:CGRectMake(0, 0, 64, 24) type:UIButtonTypeCustom title:@"暂存" titleColor:COLOR_HEX(0x333333) layercorne:13 font:[UIFont fontWithName:@"PingFangSC-Regular" size: 16] backgroudColor:[UIColor clearColor] AndActionBlock:^(UIButton * _Nonnull btn) {
        weakSelf.inforModel.status = @"6";
        NSDictionary *param = [self.inforModel properties_aps];
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
           [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}
/// 创建表单的view
-(void)createFormView{
    WS(weakSelf)
    self.formview = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .registerRow([LKUFOpenShopHeaderRow class], [LKUFOpenShopHeaderRowCell class])
        .registerRow([LKUFPictureRow class], [LKUFPictureRowCell class])
        .registerRow([LKUFOpenShopBottomButtonRow class], [LKUFOpenShopBottomButtonRowCell class])
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .titleStyle([UFRowTitleStyle makeTitleStyle:^(UFRowTitleStyleMaker * _Nonnull make) {
               make
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor)
                .textAlignment(NSTextAlignmentLeft);
            }])
            .valueStyle([UFTextStyle makeTextStyle:^(UFRowTextStyleMaker * _Nonnull make) {
                make
                .textAlignment(NSTextAlignmentRight)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopHeaderRow *row = [[LKUFOpenShopHeaderRow alloc] init];
                row.headerImage = [UIImage imageNamed:@"编组 6"];
                row.height = (WIDTH - 26)/7 + 20;
                return row;
            })
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"商户名称")
                .name(@"merchant_name")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.merchant_name = value;
                })
                .value(weakSelf.inforModel.merchant_name);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .maxLength(12)
                .height(RowHeightDefault)
                .title(@"商户简称")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.merchant_jiancheng = value;
                })
                .value(weakSelf.inforModel.merchant_jiancheng);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"总店",@"单门店"])
                .title(@"店铺类型")
                .name(@"店铺类型")
                .value([self.inforModel.store_type isEqualToString:@"0"] ? @"总店":@"单门店")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    if ([value isEqualToString:@"总店"]) {
                        self.inforModel.store_type = @"0";
                    }
                    if ([value isEqualToString:@"单门店"]) {
                        self.inforModel.store_type = @"-1";
                    }
                })
                .height(RowHeightDefault)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFAreaPickerRow makeAreaPickerRow:^(UFAreaPickerRowMaker * _Nonnull make) {
                make
                .areaSeparator(@",")
                .title(@"店铺地址")
                .name(@"address")
                .value([NSString stringWithFormat:@"%@%@%@",weakSelf.inforModel.province,weakSelf.inforModel.city,weakSelf.inforModel.county])
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    NSArray *addressArray = [value componentsSeparatedByString:@","];
                    if (addressArray.count == 3) {
                        weakSelf.inforModel.province = addressArray[0];
                        weakSelf.inforModel.city = addressArray[1];
                        weakSelf.inforModel.county = addressArray[2];
                    }else{
                        weakSelf.inforModel.province = addressArray[0];
                        weakSelf.inforModel.county = addressArray[1];
                        if ([weakSelf.inforModel.province containsString:@"市"]) {
                            weakSelf.inforModel.county = addressArray[1];
                            weakSelf.inforModel.city = [weakSelf.inforModel.province mutableCopy];
                            weakSelf.inforModel.province = [[weakSelf.inforModel.province componentsSeparatedByString:@"市"] firstObject];
                        }
                    }

                })
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"详细地址")
                .name(@"详细地址")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.address = value;
                })
                .value(weakSelf.inforModel.address);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"营业执照号")
                .name(@"营业执照号")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.business_license_number = value;
                })
                .value(weakSelf.inforModel.business_license_number);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFPictureRow *pictureRow = [[LKUFPictureRow alloc] init];
                pictureRow.pictureNumbers = 1;
                pictureRow.headerTitle = @"营业执照照片";
                pictureRow.picturesArray = [[NSMutableArray alloc] initWithArray:@[weakSelf.inforModel.business_license]];
                pictureRow.height = 145;
                pictureRow.uploadImageBlock = ^(NSInteger selectValue, UIImageView * _Nonnull selecteImageV) {
                    dispatch_group_notify(self->_group, dispatch_get_main_queue(), ^{
                        dispatch_semaphore_signal(self->semaphore);
                        weakSelf.pictureTapSelectIndex = 7;
                        [weakSelf showAlertChooseVc];
                    });
                };
                return pictureRow;
            })
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFPictureRow *pictureRow = [[LKUFPictureRow alloc] init];
                pictureRow.pictureNumbers = 2;
                pictureRow.headerTitle = @"收单服务协议（选传，用于专属通道）";
                pictureRow.titlesPlaceArray = @[@"+收单服务协议",@"+收单服务协议"];
                pictureRow.picturesArray = [[NSMutableArray alloc] initWithArray:@[weakSelf.inforModel.receipt_img_one,weakSelf.inforModel.receipt_img_two]];
                pictureRow.height = 145;
                pictureRow.uploadImageBlock = ^(NSInteger selectValue, UIImageView * _Nonnull selecteImageV) {
                    dispatch_group_notify(self->_group, dispatch_get_main_queue(), ^{
                        dispatch_semaphore_signal(self->semaphore);
                        weakSelf.pictureTapSelectIndex = 8;
                        [weakSelf showAlertChooseVc];
                    });
                };
                return pictureRow;
            })
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopBottomButtonRow *buttonRow = [[LKUFOpenShopBottomButtonRow alloc] init];
                buttonRow.height = 250;
                buttonRow.actionBlock = ^{
                    if ([NSString isBlankString:weakSelf.inforModel.merchant_jiancheng])  {
                        [SVProgressHUD showInfoWithStatus:@"请填写商户简称"];
                        return ;
                    }
                    
                    if ([NSString isBlankString:weakSelf.inforModel.address])  {
                        [SVProgressHUD showInfoWithStatus:@"请选择店铺地址"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.address])  {
                        [SVProgressHUD showInfoWithStatus:@"请填写详细地址"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.business_license])  {
                        [SVProgressHUD showInfoWithStatus:@"请选择营业执照照片"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.business_license_number])  {
                        [SVProgressHUD showInfoWithStatus:@"请选择营业执照号"];
                        return ;
                    }
                    weakSelf.inforModel.status = @"6";
                    NSDictionary *param = [self.inforModel properties_aps];
                    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
                        
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                       [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        LKOpenShopStepThreeViewController *stepThreeVc = [[LKOpenShopStepThreeViewController alloc] init];
                        stepThreeVc.inforModel = weakSelf.inforModel;
                        [weakSelf.navigationController pushViewController:stepThreeVc animated:YES];
                    } failure:^(NSString * _Nullable errorMessage) {
                        
                    }];

                };
                return buttonRow;
            });
        }])
        .addToSuperView(self.view);
    }];
    [self.formview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(NAVIGATION_BAR_HEIGHT);
        make.bottom.equalTo(self.view);
    }];
}

/// 创建小微商户的表单
-(void)createXiaoVFormView{
    WS(weakSelf)
    self.formview = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .registerRow([LKUFOpenShopHeaderRow class], [LKUFOpenShopHeaderRowCell class])
        .registerRow([LKUFPictureRow class], [LKUFPictureRowCell class])
        .registerRow([LKUFOpenShopBottomButtonRow class], [LKUFOpenShopBottomButtonRowCell class])
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .titleStyle([UFRowTitleStyle makeTitleStyle:^(UFRowTitleStyleMaker * _Nonnull make) {
               make
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor)
                .textAlignment(NSTextAlignmentLeft);
            }])
            .valueStyle([UFTextStyle makeTextStyle:^(UFRowTextStyleMaker * _Nonnull make) {
                make
                .textAlignment(NSTextAlignmentRight)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopHeaderRow *row = [[LKUFOpenShopHeaderRow alloc] init];
                row.headerImage = [UIImage imageNamed:@"编组 6"];
                row.height = (WIDTH - 26)/7 + 20;
                return row;
            })
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"商户名称")
                .name(@"merchant_name")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.merchant_name = value;
                })
                .value(weakSelf.inforModel.merchant_name);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .maxLength(12)
                .height(RowHeightDefault)
                .title(@"商户简称")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.merchant_jiancheng = value;
                })
                .value(weakSelf.inforModel.merchant_jiancheng);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"总店",@"单门店"])
                .title(@"店铺类型")
                .name(@"店铺类型")
                .value([self.inforModel.store_type isEqualToString:@"0"] ? @"总店":@"单门店")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    if ([value isEqualToString:@"总店"]) {
                        self.inforModel.store_type = @"0";
                    }
                    if ([value isEqualToString:@"单门店"]) {
                        self.inforModel.store_type = @"-1";
                    }
                })
                .height(RowHeightDefault)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFAreaPickerRow makeAreaPickerRow:^(UFAreaPickerRowMaker * _Nonnull make) {
                make
                .areaSeparator(@",")
                .title(@"店铺地址")
                .name(@"address")
                .value([NSString stringWithFormat:@"%@%@%@",weakSelf.inforModel.province,weakSelf.inforModel.city,weakSelf.inforModel.county])
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    NSArray *addressArray = [value componentsSeparatedByString:@","];
                    if (addressArray.count == 3) {
                        weakSelf.inforModel.province = addressArray[0];
                        weakSelf.inforModel.city = addressArray[1];
                        weakSelf.inforModel.county = addressArray[2];
                        
                    }else{
                        weakSelf.inforModel.province = addressArray[0];
                        weakSelf.inforModel.county = addressArray[1];
                        if ([weakSelf.inforModel.province containsString:@"市"]) {
                            weakSelf.inforModel.county = addressArray[1];
                            weakSelf.inforModel.city = [weakSelf.inforModel.province mutableCopy];
                            weakSelf.inforModel.province = [[weakSelf.inforModel.province componentsSeparatedByString:@"市"] firstObject];
                        }
                        
                    }

                })
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"详细地址")
                .name(@"详细地址")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.address = value;
                })
                .value(weakSelf.inforModel.address);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopBottomButtonRow *buttonRow = [[LKUFOpenShopBottomButtonRow alloc] init];
                buttonRow.height = 250;
                buttonRow.actionBlock = ^{
                    if ([NSString isBlankString:weakSelf.inforModel.merchant_jiancheng])  {
                        [SVProgressHUD showInfoWithStatus:@"请填写商户简称"];
                        return ;
                    }
                    
                    if ([NSString isBlankString:weakSelf.inforModel.address])  {
                        [SVProgressHUD showInfoWithStatus:@"请选择店铺地址"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.address])  {
                        [SVProgressHUD showInfoWithStatus:@"请填写详细地址"];
                        return ;
                    }
                    weakSelf.inforModel.status = @"6";
                    NSDictionary *param = [self.inforModel properties_aps];
                    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
                        
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                       [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        LKOpenShopStepThreeViewController *stepThreeVc = [[LKOpenShopStepThreeViewController alloc] init];
                        stepThreeVc.inforModel = weakSelf.inforModel;
                        [weakSelf.navigationController pushViewController:stepThreeVc animated:YES];
                    } failure:^(NSString * _Nullable errorMessage) {
                        
                    }];
                };
                return buttonRow;
            });
        }])
        .addToSuperView(self.view);
    }];
    [self.formview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(NAVIGATION_BAR_HEIGHT);
        make.bottom.equalTo(self.view);
    }];
}

/// 创建个人表单View
-(void)createPesonFormView{
    WS(weakSelf)
    self.formview = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .registerRow([LKUFOpenShopHeaderRow class], [LKUFOpenShopHeaderRowCell class])
        .registerRow([LKUFPictureRow class], [LKUFPictureRowCell class])
        .registerRow([LKUFOpenShopBottomButtonRow class], [LKUFOpenShopBottomButtonRowCell class])
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .titleStyle([UFRowTitleStyle makeTitleStyle:^(UFRowTitleStyleMaker * _Nonnull make) {
               make
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor)
                .textAlignment(NSTextAlignmentLeft);
            }])
            .valueStyle([UFTextStyle makeTextStyle:^(UFRowTextStyleMaker * _Nonnull make) {
                make
                .textAlignment(NSTextAlignmentRight)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopHeaderRow *row = [[LKUFOpenShopHeaderRow alloc] init];
                row.headerImage = [UIImage imageNamed:@"编组 6"];
                row.height = (WIDTH - 26)/7 + 20;
                return row;
            })
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"商户名称")
                .name(@"merchant_name")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.merchant_name = value;
                })
                .value(weakSelf.inforModel.merchant_name);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .maxLength(12)
                .height(RowHeightDefault)
                .title(@"商户简称")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.merchant_jiancheng = value;
                })
                .value(weakSelf.inforModel.merchant_jiancheng);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"总店",@"单门店"])
                .title(@"店铺类型")
                .name(@"店铺类型")
                .value([self.inforModel.store_type isEqualToString:@"0"] ? @"总店":@"单门店")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    if ([value isEqualToString:@"总店"]) {
                        self.inforModel.store_type = @"0";
                    }
                    if ([value isEqualToString:@"单门店"]) {
                        self.inforModel.store_type = @"-1";
                    }
                })
                .height(RowHeightDefault)
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFAreaPickerRow makeAreaPickerRow:^(UFAreaPickerRowMaker * _Nonnull make) {
                make
                .areaSeparator(@",")
                .title(@"店铺地址")
                .name(@"address")
                .value([NSString stringWithFormat:@"%@%@%@",weakSelf.inforModel.province,weakSelf.inforModel.city,weakSelf.inforModel.county])
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    NSArray *addressArray = [value componentsSeparatedByString:@","];
                    if (addressArray.count == 3) {
                        weakSelf.inforModel.province = addressArray[0];
                        weakSelf.inforModel.city = addressArray[1];
                        weakSelf.inforModel.county = addressArray[2];
                    }else{
                        weakSelf.inforModel.province = addressArray[0];
                        weakSelf.inforModel.county = addressArray[1];
                         if ([weakSelf.inforModel.province containsString:@"市"]) {
                            weakSelf.inforModel.county = addressArray[1];
                            weakSelf.inforModel.city = [weakSelf.inforModel.province mutableCopy];
                            weakSelf.inforModel.province = [[weakSelf.inforModel.province componentsSeparatedByString:@"市"] firstObject];

                        }
                    }

                })
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"详细地址")
                .name(@"详细地址")
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, NSString * _Nonnull value) {
                    weakSelf.inforModel.address = value;
                })
                .value(weakSelf.inforModel.address);
            }])
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFPictureRow *pictureRow = [[LKUFPictureRow alloc] init];
                pictureRow.pictureNumbers = 2;
                pictureRow.headerTitle = @"收单服务协议（选传，用于专属通道）";
                pictureRow.titlesPlaceArray = @[@"+收单服务协议",@"+收单服务协议"];
                pictureRow.picturesArray = [[NSMutableArray alloc] initWithArray:@[weakSelf.inforModel.receipt_img_one,weakSelf.inforModel.receipt_img_two]];
                pictureRow.height = 145;
                pictureRow.uploadImageBlock = ^(NSInteger selectValue, UIImageView * _Nonnull selecteImageV) {
                    dispatch_group_notify(self->_group, dispatch_get_main_queue(), ^{
                        dispatch_semaphore_signal(self->semaphore);
                        weakSelf.pictureTapSelectIndex = 6;
                        [weakSelf showAlertChooseVc];
                    });
                };
                return pictureRow;
            })
            .addRowWithBlock(^__kindof UFRow * _Nonnull{
                LKUFOpenShopBottomButtonRow *buttonRow = [[LKUFOpenShopBottomButtonRow alloc] init];
                buttonRow.height = 250;
                buttonRow.actionBlock = ^{

                    if ([NSString isBlankString:weakSelf.inforModel.merchant_jiancheng])  {
                        [SVProgressHUD showInfoWithStatus:@"请填写商户简称"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.address])  {
                        [SVProgressHUD showInfoWithStatus:@"请选择店铺地址"];
                        return ;
                    }
                    if ([NSString isBlankString:weakSelf.inforModel.address])  {
                        [SVProgressHUD showInfoWithStatus:@"请填写详细地址"];
                        return ;
                    }
                    
                    weakSelf.inforModel.status = @"6";
                    NSDictionary *param = [self.inforModel properties_aps];
                    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenInformationEditUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
                        
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                       [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        LKOpenShopStepThreeViewController *stepThreeVc = [[LKOpenShopStepThreeViewController alloc] init];
                        stepThreeVc.inforModel = weakSelf.inforModel;
                        [weakSelf.navigationController pushViewController:stepThreeVc animated:YES];
                    } failure:^(NSString * _Nullable errorMessage) {
                        
                    }];
                };
                return buttonRow;
            });
        }])
        .addToSuperView(self.view);
    }];
    [self.formview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(NAVIGATION_BAR_HEIGHT);
        make.bottom.equalTo(self.view);
    }];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {
        UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage];
        LKUFPictureRow *row = [self.formview findRowInRange:UFMakeRange(0, self.pictureTapSelectIndex)];
        NSLog(@"选中的%ld",row.selectImageV.tag);
        row.selectImageV.image = photo;
        self.selcetedUploadImage = row.selectImageV.image;
        if (self.pictureTapSelectIndex == 7) {
              dispatch_group_enter(_group);
              dispatch_group_async(_group, dispatch_get_main_queue(), ^{
                  [SVProgressHUD showWithStatus:@"图片上传中..."];
                    [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:ImageUploadUrl parameters:nil imageArray:@[self.selcetedUploadImage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                        if ([NSString isBlankString:responseObject[@"data"]]) {
                            [SVProgressHUD showInfoWithStatus:@"图片未上传成功，请重新选择"];
                            return ;
                        }
                        dispatch_group_leave(self->_group);
                        dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
                            NSLog(@"执行结束");
                        [SVProgressHUD dismiss];
                        if ([responseObject[@"code"] isEqualToString:@"success"]) {
                            self.inforModel.business_license = responseObject[@"data"];
                        }else{
                      dispatch_group_leave(self->_group);
                      [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        }
                
                    } failure:^(NSString * _Nullable error) {
                
                    }];
            });

        }else{
            dispatch_group_enter(_group);
            dispatch_group_async(_group, dispatch_get_main_queue(), ^{
                [SVProgressHUD showWithStatus:@"图片上传中..."];
                    [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:ImageUploadUrl parameters:nil imageArray:@[self.selcetedUploadImage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                
                    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                        if ([responseObject[@"code"] isEqualToString:@"success"]) {
                            if ([NSString isBlankString:responseObject[@"data"]]) {
                                [SVProgressHUD showInfoWithStatus:@"图片未上传成功，请重新选择"];
                                return ;
                            }
                            switch (row.selectImageV.tag - 1000) {
                                case 0:
                                {
                                    self.inforModel.receipt_img_one = responseObject[@"data"];
                                }
                                    break;
                                case 1:
                                {
                                    self.inforModel.receipt_img_two = responseObject[@"data"];
                                }
                                    break;
                                default:
                                    break;
                            }
                            dispatch_group_leave(self->_group);
                              dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
                              NSLog(@"执行结束");
                                  [SVProgressHUD dismiss];
                        }else{
                dispatch_group_leave(self->_group);
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                        }
                
                    } failure:^(NSString * _Nullable error) {
                
                    }];
            });

        }

    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos{
    LKUFPictureRow *row = [self.formview findRowInRange:UFMakeRange(0, self.pictureTapSelectIndex)];
        row.selectImageV.superview.userInteractionEnabled = NO;
    NSLog(@"选中的%ld",row.selectImageV.tag);
    row.selectImageV.image = photos[0];
    self.selcetedUploadImage = row.selectImageV.image;
    if (self.pictureTapSelectIndex == 7) {
        dispatch_group_enter(_group);
          dispatch_group_async(_group, dispatch_get_main_queue(), ^{
               [SVProgressHUD showWithStatus:@"图片上传中..."];
                [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:ImageUploadUrl parameters:nil imageArray:@[self.selcetedUploadImage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
            
                } success:^(BOOL isSuccess, id  _Nullable responseObject) {
    row.selectImageV.superview.userInteractionEnabled = YES;
                    if ([responseObject[@"code"] isEqualToString:@"success"]) {
                        if ([NSString isBlankString:responseObject[@"data"]]) {
                            [SVProgressHUD showInfoWithStatus:@"图片未上传成功，请重新选择"];
                            return ;
                        }
                        self.inforModel.business_license = responseObject[@"data"];
                        dispatch_group_leave(self->_group);
                        dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
                            NSLog(@"执行结束");
                        [SVProgressHUD dismiss];
                    }else{
                  dispatch_group_leave(self->_group);
                  [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                    }
            
                } failure:^(NSString * _Nullable error) {
            
                }];
        });

    }else{
        dispatch_group_enter(_group);
        dispatch_group_async(_group, dispatch_get_main_queue(), ^{
            [SVProgressHUD showWithStatus:@"图片上传中..."];
                [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:ImageUploadUrl parameters:nil imageArray:@[self.selcetedUploadImage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
            
                } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                NSLog(@"执行结束");
                        row.selectImageV.superview.userInteractionEnabled = YES;
                    if ([responseObject[@"code"] isEqualToString:@"success"]) {
                        if ([NSString isBlankString:responseObject[@"data"]]) {
                            [SVProgressHUD showInfoWithStatus:@"图片未上传成功，请重新选择"];
                            return ;
                        }
                        switch (row.selectImageV.tag - 1000) {
                            case 0:
                            {
                                self.inforModel.receipt_img_one = responseObject[@"data"];
                            }
                                break;
                            case 1:
                            {
                                self.inforModel.receipt_img_two = responseObject[@"data"];
                            }
                                break;
                            default:
                                break;
                                
                        }
                        dispatch_group_leave(self->_group);
                          dispatch_semaphore_wait(self->semaphore, DISPATCH_TIME_FOREVER);
                              [SVProgressHUD dismiss];
                    }else{
                dispatch_group_leave(self->_group);
                NSLog(@"执行结束");
               [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                    }
            
                } failure:^(NSString * _Nullable error) {
            
                }];
        });

    }

}

@end
